<?php

namespace app\common\command;

use app\common\enums\ClassHourStatusEnum;
use app\common\model\banxi\core\CoreClassHourDetail;
use think\console\Command;
use think\console\Input;
use think\console\Output;

/**
 * 配置
 */
class ClassHourAutoCancel extends Command
{
    protected function configure()
    {
        $this->setName('classHourAutoCancel')
            // ->addArgument('name', Argument::OPTIONAL, "your name")
            // ->addOption('city', null, Option::VALUE_REQUIRED, 'city name')
            ->setDescription('automatically cancel the class time transaction flow');
    }

    protected function execute(Input $input, Output $output)
    {
        $output->writeln("自动取消课时交易流水任务开始");
        $this->doCommand();
        $output->writeln("自动取消课时交易流水任务结束");
    }

    protected function doCommand()
    {
        $dateTime = strtotime('-30 minutes');
        $coreClassHourDetail = new CoreClassHourDetail();
        $coreClassHourDetail->where([
            ['isLinePay', '=', 1],
            ['status', '=', ClassHourStatusEnum::IN],
            ['create_time', '<', $dateTime]
        ])->update(['status' => ClassHourStatusEnum::CANCEL]);
        return true;
    }

}